package com.deliinsns.sys;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.List;
import com.deliinsns.sys.util.DateJsonValueProcessor;
import com.deliinsns.sys.util.TimestampJsonValueProcessor;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
public class Messenger {
	
	private Integer state= 202;
	private String msg= "";
	private String msgCode="";
	private Object bean= null;
	private List items= null;
	private Integer total=0;
	
	@Override
	public String toString() {
		JSONObject jo= new JSONObject();		
		jo.put("state", state);
		jo.put("msg", msg);
		jo.put("msgCode", msgCode);
		JsonConfig config = new JsonConfig();
		config.registerJsonValueProcessor(Timestamp.class,new TimestampJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
		config.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd"));
		if(bean!=null){
			jo.put("bean", JSONObject.fromObject(bean,config));
		}
		if(items!=null){	//考虑到分页
			jo.put("items", JSONArray.fromObject(items,config));
			jo.put("total", total);
		}
		return jo.toString();
	}

	public String getMsg() {
		return msg;
	}
	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
	public List getItems() {
		return items;
	}
	public void setItems(List items) {
		this.items = items;
	}
	public Integer getTotal() {
		return total;
	}
	public void setTotal(Integer total) {
		this.total = total;
	}
	public Object getBean() {
		return bean;
	}
	public void setBean(Object bean) {
		this.bean = bean;
	}
	public String getMsgCode() {
		return msgCode;
	}
	public void setMsgCode(String msgCode) {
		this.msgCode = msgCode;
	}
}
